﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Universum.Infrastructure.Persistence;
using Universum.Infrastructure.Persistence.Queries;
using Universum.Infrastructure.Utils.Extensions;
using Universum.Model.Domain;
namespace Universum.Model.Services
{
	public class FileResourceService : IResourceService
	{
		IRepository _repository;
		IFileService _fileService;

		public FileResourceService(IRepository repository, IFileService fileService)
		{
			_repository = repository;
			_fileService = fileService;
		}
		public string GetRepresentationForContentType(string contentType)
		{

			return @"";
		}
		#region IResourceService Members

		public void Save(Universum.Model.Domain.Resource resource)
		{
			throw new NotImplementedException();
		}

		public Universum.Model.Domain.ResourceStreamContentDecorator FindById(Guid resourceId)
		{
			var resource_to_return = _repository
				.Load<Resource>(resourceId);
			if (resource_to_return.IsNotNull())
			{
				if (_fileService.FileExists(resource_to_return.Path).IsFalse())
				{
					_repository.Remove(resource_to_return);
					return null;
				}
				else
					return
									new ResourceStreamContentDecorator(resource_to_return
									, _fileService.GetStreamFor(resource_to_return.Path));
			}
			else return null;

		}

		private System.IO.Stream GetStreamFor(string p)
		{
			throw new NotImplementedException();
		}

		#endregion
	}
}
